
import { pageLimit } from '../../stored'
import { save } from '../../utils/storage'
import { STORE_KEY_CONFIG_PAGE_LIMIT } from '../../constants'

const state = {
  pageLimit: pageLimit
}

const mutations = {
  UPDATE (state, config) {
    state.pageLimit = config.pageLimit || state.pageLimit
  }
}

const actions = {
  updateGlobalConfig ({ commit, state, dispatch }, config) {
    commit('UPDATE', config)
    save(STORE_KEY_CONFIG_PAGE_LIMIT, state.pageLimit)
  }
}

const getters = {
  globalConfig (state) {
    return state
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}
